package com.hankol.material.adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hankol.material.R;
import com.hankol.material.bean.FolderListBean;

import java.util.List;


public class SelectFolderAdapter extends BaseMultiItemQuickAdapter<FolderListBean, BaseViewHolder> {
    public static final int ITEM_SELECT = 0;
    public static final int ITEM_CREATE = 1;

    public SelectFolderAdapter(List<FolderListBean> data) {
        super(data);
        addItemType(ITEM_SELECT, R.layout.item_select_folder);
        addItemType(ITEM_CREATE, R.layout.item_create_folder);
    }

    @Override
    protected void convert(BaseViewHolder helper, FolderListBean item) {
        switch (helper.getItemViewType()) {
            case ITEM_SELECT:
                helper.setText(R.id.tv_folder_name, item.getName());
                helper.addOnClickListener(R.id.iv_add_to_folder);
                break;
            case ITEM_CREATE:
                helper.setText(R.id.tv_create_new_folder, "创建并添加");
                helper.addOnClickListener(R.id.tv_create_new_folder);
                EditText etvName = helper.getView(R.id.etv_folder_name);
                etvName.addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                    }

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {

                    }

                    @Override
                    public void afterTextChanged(Editable s) {
                        if (s.toString().length() > 0) {
                            item.setName(s.toString());
                        }
                    }
                });
                break;
        }

    }
}
